//
//  FaBuSelect.m
//  加加加加加加
//
//  Created by Cheng on 16/2/26.
//  Copyright © 2016年 Cheng. All rights reserved.
//

#import "FaBuSelect.h"
#import "FaBuLocalView.h"
@interface FaBuSelect ()

@end

@implementation FaBuSelect

-(instancetype)initWithFrame:(CGRect)frame{

    if ([super initWithFrame:frame]) {
        
        [self CreatUI];
        
    }
    return self;
}


-(void)CreatUI{
    
    self.addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 
    self.addBtn.frame = CGRectMake(10, 5, H(self)/2-10, H(self)/2-10);
    
    [self.addBtn setImage:[UIImage imageNamed:@"release"] forState:UIControlStateNormal];
    
    [self.addBtn addTarget:self action:@selector(HaClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.addBtn];
    
    
    CGRect rect =CGRectMake(0, Y(self.addBtn), 0, Height(self.addBtn)-6);
    self.wenziBtn = [self btnCreat:@"文字"];
    self.wenziBtn.frame = rect;

    self.tupianBtn = [self btnCreat:@"图片"];
    self.tupianBtn.frame = rect;
    
    self.paizhaoBtn = [self btnCreat:@"拍照"];
    self.paizhaoBtn.frame = rect;
    
    FaBuLocalView *local = [[NSBundle mainBundle]loadNibNamed:@"FaBuLocalView" owner:nil options:nil].lastObject;
    
    local.frame = CGRectMake(0, H(self)/2, SCREEN_WIDTH, H(self)/2);
    [self addSubview:local];
    
}

-(void)HaClick:(UIButton *)btn{
    btn.selected = !btn.selected;
    
    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
    
    if (btn.selected) {
        
        [UIView animateWithDuration:0.3 animations:^{
            
            btn.transform=CGAffineTransformMakeRotation((M_PI/2)/2);
            [self TranChangeBtnWhithWW:SCREEN_WIDTH*0.15];
            
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            
            btn.transform = CGAffineTransformMakeRotation(0);
            [self TranChangeBtnWhithWW:0];
            
        }];
    }
}

-(void)TranChangeBtnWhithWW:(CGFloat)ww{
    
    self.wenziBtn.x = Width(self.addBtn)+10 ;
    self.wenziBtn.width = ww;
    
    self.tupianBtn.x=Width(self.addBtn)+10+ww+10;
    
    self.tupianBtn.width = ww;
    
    self.paizhaoBtn.x=Width(self.addBtn)+10+(ww+10)*2;
    
    self.paizhaoBtn.width = ww;

}


-(UIButton *)btnCreat:(NSString *)title{

    UIButton *bnt  = [UIButton buttonWithType:UIButtonTypeCustom];
    bnt.backgroundColor = mainColor;
    [bnt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bnt setTitle:title forState:UIControlStateNormal];
    bnt.titleLabel.font  = font(SCREEN_WIDTH*0.04);
    [self addSubview:bnt];
    
    radius(bnt, H(self.addBtn)/2);
    return bnt;
}


@end
